package Servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import Biz.ForgetpwdBiz;
import Biz.ForgetpwdBizImpl;
import Item.ForgetPassword;

/**
 * Servlet implementation class ForgetPasswordServlet
 */

public class CheckPasswordServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public CheckPasswordServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		
		request.setCharacterEncoding("utf-8");
		response.setCharacterEncoding("utf-8");
		//response.setContentType("text/html;charset=utf-8");
		String studentnumber = request.getParameter("studentnumber");
		String phone = request.getParameter("phone");

		ForgetPassword fp = new ForgetPassword();
		fp.setStudentnumber(studentnumber);
		fp.setPhone(phone);
		System.out.println(fp);
		ForgetpwdBiz biz = new ForgetpwdBizImpl();
		boolean ret = biz.isCheckForget(fp);
		HttpSession session = request.getSession();
	    session.setAttribute("fp", studentnumber);
		if (ret){
			request.getRequestDispatcher("ForgetPassword2.jsp").forward(request, response);
		} else {
			response.sendRedirect("ForgetPassword.jsp");
		}
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request,response);
	}
}
